package com.example.hello1;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class currency_fetch extends AppCompatActivity {
    private  String Tag="currency_change";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_currency_fetch);
        Intent intent = getIntent();
        float dollar2 = intent.getFloatExtra("dollar_rate", 0.0f);
        float euro2 = intent.getFloatExtra("euro_rate", 0.0f);
        float won2 = intent.getFloatExtra("won_rate", 0.0f);
       //日志输出

        Log.i(Tag,"new dollar"+dollar2);
        Log.i(Tag,"new euro"+euro2);
        Log.i(Tag,"new won"+won2);
         //得到控件，设置显示汇率
        EditText edit = findViewById(R.id.edo_rate);
        EditText edit1 = findViewById(R.id.eeuro_rate);
        EditText edit2 = findViewById(R.id.ewon_rate);
        edit.setText(""+dollar2);
        edit1.setText(""+euro2);
        edit2.setText(""+won2);
    }
    //save——button 修改汇率
    public void func(View btn){

        EditText edit = findViewById(R.id.edo_rate);
        float new_dollar = Float.parseFloat(edit.getText().toString());
        EditText edit1 = findViewById(R.id.eeuro_rate);
        float new_euro = Float.parseFloat(edit1.getText().toString());
        EditText edit2 = findViewById(R.id.ewon_rate);
        float new_won = Float.parseFloat(edit2.getText().toString());

        SharedPreferences sp = getSharedPreferences("save_currency", Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putFloat("dollar_rate",new_dollar);
        editor.putFloat("euro_rate",new_euro);
        editor.putFloat("won_rate",new_won);

        editor.apply();

        Intent intent = getIntent();
        intent.putExtra("dollar_rate",new_dollar);
        intent.putExtra("euro_rate",new_euro);
        intent.putExtra("won_rate",new_won);
        setResult(506,intent);
        finish();//关闭当前窗口，回到之前的窗口
    }

}